package com.groupfifteen.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.groupfifteen.dao.AnswerDao;
import com.groupfifteen.vo.AnswerVo;
import com.groupfifteen.vo.QuestionVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AnswerServiceImpl implements AnswerService{
    private final AnswerDao answerMapper;

    /**
     * 查询题库 分页
     *
     * @param page     分页对象
     * @param subject  学科
     * @param section  章节
     * @param question 问题
     * @return 题目
     */
    @Override
    public IPage<AnswerVo> findAll(Page<AnswerVo> page, String subject, String section, String question) {
        subject = (subject.equals("@") ? "" : subject);
        section = (section.equals("@") ? "" : section);
        question = (question.equals("@") ? "" : question);
        return answerMapper.findAll(page, subject, section, question);
    }

    /**
     * 根据类型和id获取题目
     *
     * @param type       类型
     * @param questionId 题目id
     * @return 题目信息
     */
    @Override
    public QuestionVo findByIdAndType(String type, Long questionId) {
        QuestionVo questionVO = new QuestionVo();
        questionVO.setType(type);
        switch (type) {
            case "选择题":
                questionVO.setMultiQuestion(answerMapper.findMultiQuestionById(questionId));
                break;
            case "判断题":
                questionVO.setJudgeQuestion(answerMapper.findJudgeQuestionById(questionId));
                break;
            case "填空题":
                questionVO.setFillQuestion(answerMapper.findFillQuestionById(questionId));
                break;
        }
        return questionVO;
    }
}
